package jp.co.mclnet.dao;

import java.io.Serializable;
import java.sql.Connection;
import java.util.Arrays;
import java.util.Iterator;

import jp.co.mclnet.exception.AlreadyExistsException;
import jp.co.mclnet.exception.AlreadyUpdatedException;
import jp.co.mclnet.exception.LogicalException;
import jp.co.mclnet.exception.NotFoundException;

public class JdbcDao implements Dao, HasColumnNames, HasConnection {

    private String[] allColumnNames;
    private Connection connection;
    private String[] keyColumnNames;
    private String tableName;
    private String[] valColumnNames;

    public JdbcDao(String tableName) {
        this(tableName, null, null, null);
    }

    public JdbcDao(String tableName, String[] allColumnNames) {
        this(tableName, allColumnNames, null, null);
    }

    public JdbcDao(String tableName, String[] allColumnNames,
            String[] keyColumnNames) {
        this(tableName, allColumnNames, keyColumnNames, null);
    }

    public JdbcDao(String tableName, String[] allColumnNames,
            String[] keyColumnNames, String[] valColumnNames) {
        super();
        this.tableName = tableName;
        this.allColumnNames = allColumnNames;
        this.keyColumnNames = keyColumnNames;
        this.valColumnNames = valColumnNames;
    }

    public <E extends Serializable> void create(E value)
            throws AlreadyExistsException, LogicalException {
        // TODO 自動生成されたメソッド・スタブ

    }

    public <E extends Serializable> int delete(E condition)
            throws NotFoundException {
        // TODO 自動生成されたメソッド・スタブ
        return 0;
    }

    public <E extends Serializable> void deleteByKey(E value)
            throws NotFoundException, AlreadyUpdatedException, LogicalException {
        // TODO 自動生成されたメソッド・スタブ
    }

    public String[] getAllColumnNames() {
        return this.allColumnNames == null ? null : Arrays.asList(
                this.allColumnNames).toArray(new String[0]);
    }

    public Connection getConnection() {
        return connection;
    }

    public String[] getKeyColumnNames() {
        return this.keyColumnNames == null ? null : Arrays.asList(
                this.keyColumnNames).toArray(new String[0]);
    }

    public String getTableName() {
        return tableName;
    }

    public String[] getValColumnNames() {
        return this.valColumnNames == null ? null : Arrays.asList(
                this.valColumnNames).toArray(new String[0]);
    }

    public <E extends Serializable> Iterator<E> like(E condition)
            throws NotFoundException, LogicalException {
        // TODO 自動生成されたメソッド・スタブ
        return null;
    }

    public <E extends Serializable> Iterator<E> read(E condition)
            throws NotFoundException, LogicalException {
        // TODO 自動生成されたメソッド・スタブ
        return null;
    }

    public <E extends Serializable> void readByKey(E value)
            throws NotFoundException, LogicalException {
        // TODO 自動生成されたメソッド・スタブ

    }

    public void setAllColumnNames(String[] allColumnNames) {
        throw new UnsupportedOperationException();
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public void setKeyColumnNames(String[] keyColumnNames) {
        throw new UnsupportedOperationException();
    }

    public void setValColumnNames(String[] valColumnNames) {
        throw new UnsupportedOperationException();
    }

    public <E extends Serializable> int update(E value, E condition)
            throws NotFoundException {
        // TODO 自動生成されたメソッド・スタブ
        return 0;
    }

    public <E extends Serializable> void updateByKey(E value)
            throws NotFoundException, AlreadyUpdatedException, LogicalException {
        // TODO 自動生成されたメソッド・スタブ

    }
}
